<?php
/**
* （6W2104）全国批量代发代扣结果明细查询
*/
class Conf6w2104 extends Abccbconf
{
    public function getTransaction()
    {
        $this->_ccbConf->getTransactionHeader();
    }

    public function getTransactionBody()
    {
        /**
         *  原请求序列号 varChar(16) F
         */
        $body['REQUEST_SN1'] = $this->parameter['REQUEST_SN1'];

        /**
         *  起始页次 Int T 整数>0,不填默认查询第一页 
         */
        $body['START_PAGE'] = $this->parameter['START_PAGE'];
        return $body;
    }

    public function validateParameter()
    {
        if ( empty($this->parameter['REQUEST_SN1']) ) {
            throw new Exception("请输入原请求序列号", 1);
        }

        if ( empty($this->parameter['START_PAGE']) ) {
            throw new Exception("请输入起始页次", 1);
        }
    }

    /**
     * 解析
     */
    public function parsesResult($response)
    {
        $response = json_decode(json_encode($response), true);
        $transaction = array();
        if ( $response['RETURN_CODE'] === '000000' ) { // 验证是否转账成功
            $transaction['message'] = $response['TX_INFO']['F_MSG'];
            $transaction['success_amount'] = (float)$response['TX_INFO']['SUCCESS_AMOUNT'];
            $transaction['success_num'] = (int)$response['TX_INFO']['SUCCESS_NUM'];
            $transaction['response_content'] = $response['TX_INFO'];
        } else {
            $transaction['message'] = $response['RETURN_MSG'];
            $transaction['response_content'] = $response['TX_INFO'];
        }

        // F_STATUS 处理结果状态 Char(1)  0：处理失败  1：处理完成  2：处理中  3：网银审批中
        switch ($response['TX_INFO']['F_STATUS']) {
            case 0:
                $transaction['status'] = 2; //失败
                break;
            case 1:
                $transaction['status'] = 3; //成功
                break;
            case 2:
                $transaction['status'] = 4; //处理中
                break;
            case 3:
                $transaction['status'] = 5; //网银审批中
                break;
            default:
                break;
        }
        $transaction['state'] = 5;
        return $transaction;
    }
}